﻿using DBUtility;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data.SqlClient;
using System.Data.SqlTypes;

namespace IYAKASAPortal.Statistics
{
    public partial class PrintCLZL : System.Web.UI.Page
    {
        private static string s_strStart { get; set; }
        private static string s_strEnd { get; set; }

        private static string strSqlst { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            btnSearch_Click(sender, e);
        }

        protected void btnSearch_Click(object sender, EventArgs e) {
            s_strStart = this.txtStart.Text;
            s_strEnd = this.txtEnd.Text;
            StringBuilder sbSql = new StringBuilder();

            DataTable dt_TempSet = new DataTable();

            if (string.IsNullOrEmpty(s_strStart) && string.IsNullOrEmpty(s_strEnd)) {
                s_strStart = "2000-01-01 00:00:00";
                s_strEnd = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                /*
                sbSql.Append("EXEC [dbo].[SP_REPORT_AJ_VEHICLE_TYPE] @StartTime=NULL,@EndTime=NULL");
                DBUtility.DbHelper.GetTable(
                    sbSql.ToString(),
                    ref dt_TempSet
                );
                 * */
            }
            else {
                s_strStart = s_strStart.Substring(0, 10);
                s_strEnd = s_strEnd.Substring(0, 10);
                s_strStart += " 00:00:00";
                s_strEnd += " 23:59:59";
            }

            DBUtility.DbStoredProcedure _sqlSpExecute = new DbStoredProcedure();
            var _sqlParam1 = _sqlSpExecute.MakeInParam("StartTime", SqlDbType.DateTime, s_strStart.Length, s_strStart);
            var _sqlParam2 = _sqlSpExecute.MakeInParam("EndTime", SqlDbType.DateTime, s_strEnd.Length, s_strEnd);
            SqlParameter[] _paramList = new SqlParameter[2];
            _paramList[0] = _sqlParam1;
            _paramList[1] = _sqlParam2;
            _sqlSpExecute.GetProcDataTable(ref dt_TempSet, "SP_REPORT_AJ_VEHICLE_TYPE", _paramList);

            this.rptList.DataSource = dt_TempSet;
            this.rptList.DataBind();
            dt_TempSet.Dispose();

        }

        protected void btnSearchAll_Click(object sender, EventArgs e) {
            txtStart.Text = "";
            txtEnd.Text = "";
            btnSearch_Click(sender, e);
        }

        protected void btnPrint_Click(object sender, EventArgs e)
        {

        }
    }
}